#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <objc/message.h>

@interface MyClass : NSObject
{
}
+ (id)sharedInstance;
@end


void myClassIMP(id _rec, SEL _cmd, int theInt)
{
	NSLog(@"dynamic added method:%d",theInt);
}

@implementation MyClass

static MyClass* shared;
- (id)init
{
    if( ( self = [super init]) != nil )
    {
       class_addMethod([MyClass class], @selector(dynGeneratedMethod:), (IMP)myClassIMP, "v@:i");
	}
	shared = self;
	return self;
}
+ (id)sharedInstance
{
	return shared;
}
@end


int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

	MyClass *theInstance = [[MyClass alloc] init];

	[theInstance dynGeneratedMethod:10];

	[[MyClass sharedInstance] dynGeneratedMethod:11];

	Class $SBIconModel = objc_getClass("MyClass");
	SEL _sel =  @selector(sharedInstance);
	Method method = class_getClassMethod($SBIconModel, _sel);
	IMP old = method_getImplementation(method);
	id SBIconModel_sharedInstanceold = old($SBIconModel, _sel);
	[SBIconModel_sharedInstanceold dynGeneratedMethod:110];




	[theInstance release];

	[pool release];

	return 0;
}

 